/**
 * Created by DukeCrushIt on 2015/7/30.
 */
//module game{
    class Hair extends egret.Bitmap{
        public type:number;
        public value:number;
        public isRemoving:boolean = false;
        public depth:number = 0;
        public static HAIR_CNT:number = 0;
        public needRecord:boolean = true;
        public gravityItem:GravityItem;
        public moveItem:MoveItem;
        public sameType:boolean=true;
        public source:number = 0;//0 auto 1 click
        public removeReferTime:number = 0;
        public constructor(){
            super();
            Hair.HAIR_CNT++;
            this.name = "hair"+Hair.HAIR_CNT;
            this.touchEnabled = true;
        }
        public setType(type:number){
            this.type = type;
            this.texture = RES.getRes(type+"");
            AnchorUtil.setAnchor(this,0.5,0.5);
        }

        public jump(){
            this.isRemoving = true;
            this.removeReferTime = Model.SYSTIME;
            this.gravityItem = GravitySystem.produce();
            this.gravityItem.displayObject = this;
            this.gravityItem.currentSpeedX = 0;
            this.gravityItem.currentSpeedY = -10*(1+Math.random());
            this.gravityItem.targetY =this.y - 120;
            this.gravityItem.overCall = this.moveToMoney;
            this.gravityItem.overCallObj = this;
            this.gravityItem.doublePhase = false;
            GravitySystem.getInstance().addItem(this.gravityItem);
        }

        public moveToMoney(){
            if( this.gravityItem!= null){
                this.gravityItem.reset();
                GravitySystem.reclaim(this.gravityItem);
                this.gravityItem = null;
            }
            var bagpos:egret.Point = this.sameType ? PetMgr.getInstance().bagPostion : PetMgr.getInstance().bagPostion1;
            this.moveItem = MoveMgr.produce();
            this.moveItem.init(this,bagpos.x,bagpos.y,500,this, this.removeSelf);
            MoveMgr.getInstance().addItem(this.moveItem);
        }

        public removeSelf(){
            if( this.parent != null)
                this.parent.removeChild(this);
            PetMgr.reclaim(this);
            if( this.moveItem != null){
                MoveMgr.reclaim(this.moveItem);
                this.moveItem = null;
            }
            //if( this.needRecord){
                //Model.updateProduceHairData(PetMgr.getInstance().curPet.petId,this.value);//fixme
                //if( Model.GLEAN_NOW && this.source == 1){
                //    Model.STOREHAIRS += this.value;
                //}
                //else{
                //    window["__glean"](PetMgr.getInstance().curPet.petId,this.value);
                //}
            //}

            //if( PetMgr.getInstance().curPet.type == Model.GOOD_TYPE_DOG){
            //    Model.me.dogHair += this.value;
            //}else{
            //    Model.me.catHair += this.value;
            //}
            SoundMgr.getInstance().playEffect(SoundMgr.GATHER);
            //PlayBar.getInstance().updateDisplay();
            //DiamondElement.getInstance().updateDisplay();
            this.isRemoving = false;
            this.depth = 0;
            this.needRecord = true;
        }
    }
//}